package leetcode;

import org.junit.Test;

/**
 * @author: feiwang_6
 * @create: 2020/4/18 13:35
 * @description:
 */
public class PalindromeNumber {
    @Test
    public void testMath(){
        System.out.println(isPalindrome(123));
        System.out.println(isPalindrome2(123));
    }

    public boolean isPalindrome(int x) {
        if (x < 0)
            return false;
        char[] chars = Integer.toString(x).toCharArray();
        int mid = chars.length >> 1, i = 0;
        while (i < mid){
            if(chars[i] == chars[chars.length - i -1]){
                i++;
                continue;
            }else {
                return false;
            }
        }
        return true;
    }
    
    public boolean isPalindrome2(int x){
        long s = 0;
        int temp = x;
        while (temp > 0){
            s = s * 10 + temp % 10;
            temp /= 10;
        }
        return s == x;
    }
}
